// DLLLoader.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>


typedef void (*RetrieveTempFilenameFuncPtr)(char *str1, char * str2);
typedef int  (*getResultFuncPtr)(int x, int y);
typedef long  (*getFuncComputer_dgtsv)(long N, long NRHS, double *DL, double *D, double *DU, double *B,long LDB);


int main(int argc, char* argv[])
{
	HINSTANCE LoadME = LoadLibrary("C:\\Work\\Developping\\Tests\\DLLLoader\\Debug\\DLLTest.dll");
	if (LoadME != 0)
		printf("LoadMe library loaded!\n");
	else
		printf("LoadMe library failed to load!\n");

	//RetrieveTempFilenameFuncPtr LibMainEntryPointFunc1;
	//getResultFuncPtr LibMainEntryPointFunc2;
	getFuncComputer_dgtsv LibMainEntryPointFunc3;
	
	//LibMainEntryPointFunc1 = (RetrieveTempFilenameFuncPtr)GetProcAddress(LoadME,"RetrieveTempFilename");
	//LibMainEntryPointFunc2 = (getResultFuncPtr)GetProcAddress(LoadME,"getResult");
	LibMainEntryPointFunc3 = (getFuncComputer_dgtsv)GetProcAddress(LoadME,"Computer_dgtsv");
	

	/*LibMainEntryPointFunc1("C:\\Work\\Developping\\Tests\\DLLLoader", "aliahmed");
	int res = LibMainEntryPointFunc2(15, 3);
	printf("\n Function result = %d \n", res);*/

	double l[] = {-1, -2, -1, -1};	
	double d[] = {2, 2, 3, 3, 1};
	double u[] = {-1, -1, -1, -2};
	double x[] = {1, 2, 3, 2, 1};

	long info = LibMainEntryPointFunc3(5, 1, l, d, u, x, 5);
	if (info != 0) 
		printf("failure with error %d\n", info);
	else
		for (int i=0; i<5; ++i) 
			printf("%5.1f\n", x[i]);
	



	FreeLibrary(LoadME);
	return 0;
}
